<template>
    <div>
        <div id="news">
            <h1>Component构造器的使用</h1>
            <h2>{{msg}}</h2>
            <hr/>
            <ul>
                <li v-for="item in users" :key="item.id" @click="handleClick">{{item.name}}</li>
            </ul>
            <hr/>
            <input @input="handleInput" :value="inputVal">
        </div>
    </div>
</template>

<script lang="ts">
import { Component, Emit, Model, Prop, Vue } from 'vue-property-decorator'
interface User{
    id:number;
    name:string;
}
@Component({
    name:"News"
})
export default class News extends Vue {
    name = 'News';
    @Prop({
        type:String,
        default:""
    })
    msg!:string;
    @Prop({
        type:Array,
        default:[]
    })
    users!:Array<User>;

    @Model("receiveChange",{type:String})
    inputVal!:string;

    @Emit("receiveInfo")
    handleClick(item:User){
        return item;
    }

    @Emit("receiveChange")
    handleInput(val:any){
        return val.target.value;
    }
}
</script>

<style scoped>

</style>
